import requestMeeting, { request } from '@/plugins/axios'
import {
	FetchDeleteParamsProps,
	FetchGetAllServersParamsProps,
	FetchGetAllServersReturnProps,
	FetchGetAllVideoParamsProps,
	FetchGetAllVideoReturnProps,
	FetchGetVideoInfoParamsProps,
	FetchGetVideoInfoReturnProps,
	FetchPauseResumeParamsProps,
	FetchUpdateSaveVideoParamsProps,
	FetchUpdateSaveVideoReturnProps,
	FetchStartVideoParamsProps,
	FetchCreateSaveVideoReturnProps,
	FetchCreateSaveVideoParamsProps,
	FetchStopParamsProps,
} from './interface'
/**
 * 获取全部终端录像信息
 * @param meetingMoid 会议moid
 * @returns
 */
export const fetchGetAllVideo = async (params: FetchGetAllVideoParamsProps) =>
	request<{ list: FetchGetAllVideoReturnProps[] }>({
		url: `/mcc/${params.meeting_id}/recorders/mts/video`,
		method: 'get',
		params: {},
	}).then((res) => (res.success ? res.list : []))

/**开始终端录像 [开始按钮、开始录像按钮]*/
export const fetchStartVideo = async (params: FetchStartVideoParamsProps) =>
	requestMeeting({
		url: `/mcc/${params.meeting_id}/recorders/mts/video`,
		method: 'post',
		data: params,
	}).then((res) => res)

/**暂停/继续 终端录像 【开始按钮、暂停按钮】*/
export const fetchPauseResumeVideo = async (params: FetchPauseResumeParamsProps) =>
	requestMeeting({
		url: `/mcc/${params.meeting_id}/recorders/mts/video/state`,
		method: 'put',
		data: params,
	}).then((res) => res)

/**停止终端录像  [结束按钮]*/
export const fetchStopVideo = async (params: FetchStopParamsProps) =>
	requestMeeting({
		url: `/mcc/${params.meeting_id}/recorders/mts/video`,
		method: 'delete',
		data: params,
	}).then((res) => res)

/** 删除终端录像 [结束按钮]*/
export const fetchDeleteVideo = async (params: FetchDeleteParamsProps) =>
	requestMeeting({
		url: `/mcc/${params.meeting_id}/recorders/mts/video/records`,
		method: 'delete',
		data: params,
	}).then((res) => res)

/** 获取终端录像信息 [录像列表中的 编辑按钮]*/
export const fetchGetVideoInfo = async (params: FetchGetVideoInfoParamsProps) =>
	requestMeeting<FetchGetVideoInfoReturnProps>({
		url: `/mcc/${params.meeting_id}/recorders/mts/video/${params.id}`,
		method: 'get',
		params: params,
	}).then((res) => (res.success ? res.data : undefined))

/** 修改再保存终端录像 []*/
export const fetchUpdateSaveVideo = async (params: FetchUpdateSaveVideoParamsProps) =>
	requestMeeting<FetchUpdateSaveVideoReturnProps[]>({
		url: `/mcc/${params.meeting_id}/recorders/mts/video/records`,
		method: 'put',
		data: params,
	}).then((res) => res)

export const fetchGetAllServers = async (params?: FetchGetAllServersParamsProps) =>
	request<{ list: FetchGetAllServersReturnProps[] }>({
		url: `/mcc/recorders/servers`,
		method: 'get',
		params: params,
	}).then((res) => (res.success ? res.list : []))

/** 保存终端录像 [创建录像按钮]*/
export const fetchCreateSaveVideo = async (params: FetchCreateSaveVideoParamsProps) =>
	request<{ list: FetchCreateSaveVideoReturnProps[] }>({
		url: `/mcc/${params.meeting_id}/recorders/mts/video/records`,
		method: 'post',
		data: params,
	}).then((res) => {
		return res
	})
